/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pkl53.validasi;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import pkl53.component.Textfield;
import pkl53.controller.SubmitControllerPekerjaan;
import pkl53.model.Kecamatan;
import pkl53.view.Blok123;

/**
 *
 * @author HP G42 (RILLA)
 */
public class B123PekerjaValidasi extends AbstractValidasi{
    private Blok123 PanelBlok123;

    /**
     * @return the PanelBlok123
     */
    public JPanel getPanelBlok123() {
        return PanelBlok123;
    }

    /**
     * @param PanelBlok123 the PanelBlok123 to set
     */
    public void setPanelBlok123(Blok123 PanelBlok123) {
        this.PanelBlok123 = PanelBlok123;
    }
    
    public void registerValidasi(){
        PanelBlok123.getB1R1().setValidator(new ValidasiB1R1());
    
    }
    

private class ValidasiB1R1 implements Validator{

    @Override
    public boolean onCheckValue(Textfield field) {
        if(PanelBlok123.getB1R1().getText().equals("05")||PanelBlok123.getB1R1().getText().equals("10")
             ||PanelBlok123.getB1R1().getText().equals("71")){
            return true;
        }
        else{
            JOptionPane.showMessageDialog(null,"kode kabupaten/kota salah");
            return false;
        }
      
    }
}

private class ValidasiB1R2 implements Validator {
        SubmitControllerPekerjaan submit = new SubmitControllerPekerjaan();
        List <Kecamatan> kecamatanList = new ArrayList<Kecamatan>();
        
        @Override
        public boolean onCheckValue(Textfield field) {
            if (PanelBlok123.getB1R2().getText().isEmpty()) {
                JOptionPane.showMessageDialog(null,"Fill the previous field first!");
                return false;
            }
            kecamatanList = submit.getKecamatan(PanelBlok123.getB1R2().getText());
            if (kecamatanList.size() > 0) {
                //BalloonTipsUtility.closeBallon();
                //panelBlok12.getLabelKecamatan().setText(listKecamatan.get(0).getNamaKecamatan());
                return true;
            } else {
//                BalloonTipsUtility.closeBallon();
               JOptionPane.showMessageDialog(null,"Kode Kecamatan salah!");
//                panelBlok12.getLabelKecamatan().setText("");
                return false;
            }

        }
    }


}
